package com.yolib.sanyi.object;

import java.lang.reflect.Field;

import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import android.content.Context;
import android.os.Build;

import com.yolib.sanyi.tool.YoliBLog;

public class TrafficObject {
	public String id;
	public String tilte;//spell error?
	public String content;
	public String showit;

	public TrafficObject() {
	}

	public void setTrafficData(NodeList element) {
		Field[] fields = TrafficObject.class.getFields();

		for(Field field: fields) {
			try {
				String value;
				for(int i = 0; i < element.getLength(); i ++)
				{
					if(Node.ELEMENT_NODE == element.item(i).getNodeType())
						if( element.item(i).getNodeName().equals(field.getName()))
						{
								if(Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1)
								{
									String value_content = new String();
									for(int j=0; j < element.item(i).getChildNodes().getLength(); j++)
									{
										value_content = value_content + element.item(i).getChildNodes().item(j).getNodeValue();
									}
									value = value_content;
								}
								else
								{
									if(element.item(i).getChildNodes().getLength() != 0)
										value = element.item(i).getFirstChild().getNodeValue();
									else
										value = "";
								}

								YoliBLog.e("value: "+value);
								field.set(this, value);
							}
					}
				} catch (IllegalArgumentException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IllegalAccessException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
	}
